package com.bsg.upm.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bsg.upm.exception.APIException;
import com.bsg.upm.http.RespJson;
import com.bsg.upm.http.RespJsonFactory;
import com.bsg.upm.service.ScaleService;

/**
 * 规模管理控制层
 * 
 * @author HCK
 *
 */
@Controller
@RequestMapping("/v1.0/scales")
public class ScaleController {

	@Resource
	private ScaleService scaleService;

	/**
	 * 【查询】
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return 操作结果
	 */
	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public RespJson listScale(@RequestParam Map<String, Object> paramMap, HttpServletResponse response) {
		RespJson respJson = null;
		try {
			Map<String, Object> searchParamMap = new HashMap<String, Object>();
			if (paramMap.containsKey("serv_type")) {
				searchParamMap.put("definitionServCode", paramMap.get("serv_type"));
			}
			if (paramMap.containsKey("subserv_type")) {
				searchParamMap.put("definitionSubServName", paramMap.get("subserv_type"));
			}
			respJson = scaleService.list(searchParamMap);
			response.setStatus(respJson.getStatus());
		} catch (APIException e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}
}
